<?php
namespace app\admin\controller;
use app\admin\model\Ad as Admodel;
use think\Request;


class Ad extends Base
{
    protected function _initialize(){
        $this->checkLogin();
        $this->menuLoad();
    }
    public function index(){
        return $this->fetch('public/help');
    }

    public function adList(){
        $ad = new Admodel();
        $where['id'] = ['neq',0];
        $rs = $ad->getAll($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function addAd(Request $request){
        if($request->post()) {
            $data = $request->post();
            $ad = new Admodel();
            $data['start_time'] = strtotime($data['start_time']);
            $data['end_time'] = strtotime($data['end_time']);
            $rs = $ad->add($data);
            if(!$rs)return $this->error('添加失败');
            return $this->success('添加成功');
        }
        return $this->fetch();
    }
}